package ystp.service;


import org.springframework.stereotype.Service;
import ystp.dao.ChuangxinchanpinMapper;
import ystp.model.Chuangxinchanpin;
import ystp.model.ChuangxinchanpinExample;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class ChuangxinchanpinService {

    @Resource
    ChuangxinchanpinMapper ddMapper;

    public boolean add (Chuangxinchanpin ddChuangxinchanpin){
        return ddMapper.insert(ddChuangxinchanpin)==1;
    }

    public List<Map<String, Object>> findChuangxinPagingByXiangmuId(String ppxiangmuId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findChuangxinPagingByXiangmuId(ppxiangmuId,mmStartIndex,ppPageSize);
    }

    public Integer getChuangxinCount(String ppXiangmuId) {
        Object mmCount = ddMapper.countChuangxinByXiangmuId(ppXiangmuId);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public List<Map<String, Object>> findChuangxinBiaojueByXiangmuId(String ppxiangmuId,String ppUserId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findChuangxinBiaojueByXiangmuId(ppxiangmuId,ppUserId,mmStartIndex,ppPageSize);
    }

    public Integer countChuangxinBiaojueByXiangmuId(String ppXiangmuId,String ppUserId) {
        Object mmCount = ddMapper.countChuangxinBiaojueByXiangmuId(ppXiangmuId,ppUserId);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public boolean isExistByXiangmuId(String ppXiangmuId){
        ChuangxinchanpinExample mmExample = new ChuangxinchanpinExample();
        mmExample.createCriteria().andXiangmuidEqualTo(ppXiangmuId);
        return ddMapper.selectByExample(mmExample).size()>0;
    }

    public boolean deleteByXiangmuId(String ppXiangmuId){
        ChuangxinchanpinExample mmExample = new ChuangxinchanpinExample();
        mmExample.createCriteria().andXiangmuidEqualTo(ppXiangmuId);
        return ddMapper.deleteByExample(mmExample)>=0;
    }

    public Chuangxinchanpin findOne(String id){
        return ddMapper.selectByPrimaryKey(id);
    }

}
